<template>
	<view class="allIndex" :style="!isLogin?'max-height:calc(100vh - var(--window-top)); ':''">
		<comp-index  ref="compIndex1" v-if="moduleNo == 'ydylapp1003'"  :isOther="isOther" :hasLeft="true" :isShare="isShare" :sharePhone="sharePhone" :shareEmail="shareEmail" :shareName="shareName" :compId="compId"></comp-index>
		<comp-index2  ref="compIndex2" v-if="moduleNo == 'ydylapp1002'" :isOther="isOther"  :sharePhone="sharePhone"  :shareEmail="shareEmail" :shareName="shareName" :isShare="isShare" :compId="compId"></comp-index2>
		<index-all ref="compIndexAll" v-if="moduleNo == 'ydylapp1001'"  :isOther="isOther" :sharePhone="sharePhone" :version="2" :isShare="isShare" :compId="compId"></index-all>
		<user-index1 ref="userIndex1" v-if="moduleNo == 'ydylapp2003'"  :isOther="isOther" :isShare="isShare" :useId="useId"></user-index1>
		<user-index2 ref="userIndex2" v-if="moduleNo == 'ydylapp2002'"  :isOther="isOther" :hasLeft="true" :isShare="isShare" :useId="useId"></user-index2>
		<index-all ref="userIndexAll" v-if="moduleNo == 'ydylapp2001'"  :isOther="isOther" :version="1" :isShare="isShare" :useId="useId"></index-all>
		<my-auth-modal></my-auth-modal>
	</view>
</template>
<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from "vuex";
	import {
		getToken,
		setToken
	} from '@/utils/token.js'
	// #ifdef MP-WEIXIN
	import {
		shareMixins
	} from '@/mixins/share'
	// #endif
	import compIndex from '@/pages/index/cardIndex/compIndex.vue'
	import compIndex2 from '@/pages/index/cardIndex/compIndex2.vue'
	import userIndex1 from '@/pages/index/cardIndex/index.vue'
	import userIndex2 from '@/pages/index/cardIndex/index2.vue'
	import indexAll from '@/pages/index/cardIndex/userIndex.vue'
	export default {
		components: {
			compIndex,
			compIndex2,
			userIndex1,
			userIndex2,
			indexAll
		},
		// #ifdef MP-WEIXIN
		mixins: [shareMixins],
		// #endif
		// 触发下拉刷新
		onPullDownRefresh() {
			switch (this.moduleNo) {
				case 'ydylapp1003':
					this.$refs['compIndex1'].init()
					break;
				case 'ydylapp1002':
					this.$refs['compIndex2'].init()
					break;
				case 'ydylapp1001':
					this.$refs['compIndexAll'].initPage()
					break;
				case 'ydylapp2003':
					this.$refs['userIndex1'].init()
					break;
				case 'ydylapp2002':
					this.$refs['userIndex2'].init()
					break;
				case 'ydylapp2001':
					this.$refs['userIndexAll'].initPage()
					break;
			}
			// 延迟关闭刷新动画
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		data() {
			return {
				shareData: {
					title: '名片王'
				},
				version: '',
				compId: '',
				useId: '',
				acPath: '',
				socket: null, //socket服务
				moduleNo: '',
				isShare:false,
				shareName:'',
				shareEmail:'',
				sharePhone:'',
				isOther:false
			}
		},
		onHide: function() {
			this.$store.commit('initShare')
		},
		computed: {
			...mapGetters(['isFresh', 'isLogin', 'userInfo']),
		},
		beforeDestroy: function() {
			this.$store.commit('initShare')
		},
		// onShow:function(){
		// 	this.$store.dispatch('queryBrowerQty', {
		// 		userId: this.craftsmanId
		// 	})
		// },
		onLoad: function(option) {
			if(option.sendObj){
				console.log("getToken('useNum')1", getToken('useNum'));
				const sendObj = JSON.parse(decodeURIComponent(option.sendObj));
				if (sendObj.sharePhone) {
					this.sharePhone = sendObj.sharePhone
				}
				if (sendObj.shareEmail) {
					this.shareEmail = sendObj.shareEmail
				}
				if (sendObj.isShare) { //分享过来的链接
					this.isShare = true
				} else {
					this.isShare = false
				}
				if (sendObj.shareName) {
					this.shareName = sendObj.shareName
				}
				if(sendObj.useNum){
					sendObj.version == 1?this.useId = sendObj.useNum:this.compId = sendObj.useNum		
				}
				if(sendObj.moduleNo){
					this.moduleNo = sendObj.moduleNo
				}
				if (sendObj.version) {
					this.version = sendObj.version
				}
				console.log("getToken('useNum')2", getToken('useNum'));
			}else{
				if(option.moduleNo){
					this.moduleNo = option.moduleNo
				}
				if(option.version){
					this.version =option.version
				}else{
					this.version = getToken('version')
				}
				if (option.compId) {
					this.compId = option.compId
				
				}else{
					this.compId = getToken('complogin')['companyId']
				}
				if (option.useId || option.craftsmanId) {
					this.useId = option.useId || option.craftsmanId
					
				}else{
					this.useId = getToken('userInfo')['craftsmanId']
				}
			}
				console.log("getToken('useNum')3", getToken('useNum'));
			if(this.version == 2 && this.compId){
				if(this.compId != getToken('complogin')['companyId']){
					this.isOther = true
					// 初始化状态
					this.$store.commit('setUseState', {
						key: '',
						obj: {
							isMyFriend: false, //是我的好友
							isObjFriend: false, //是对方的好友
							inMyList: false, //别人在我的黑名单中
							inObjList: false, //我在别人的黑名单中
							isApply: false //是否在申请中
						}
					});
					this.$store.dispatch('friendsStatus', this.compId)
					//调取请求他人网页api
					this.$store.dispatch('isToOther', {
						userId: this.compId,
						version: 2
					})
				}else{
					this.isOther = false
				}
				//当前名片访问数据
				this.$store.dispatch('queryBrowerQty', {
					compId: this.compId
				})
			}else if(this.version == 1 && this.useId){
				if(this.useId != getToken('userInfo')['craftsmanId']){
					this.isOther = true
					// 初始化状态
					this.$store.commit('setUseState', {
						key: '',
						obj: {
							isMyFriend: false, //是我的好友
							isObjFriend: false, //是对方的好友
							inMyList: false, //别人在我的黑名单中
							inObjList: false, //我在别人的黑名单中
							isApply: false //是否在申请中
						}
					});
					this.$store.dispatch('friendsStatus', this.useId)
					//调取请求他人网页api
					this.$store.dispatch('isToOther', {
						userId: this.useId,
						version: 1
					})
				}else{
					this.isOther = false
				}
				//当前名片访问数据
				this.$store.dispatch('queryBrowerQty', {
					userId: this.useId
				})	
			}
				console.log("getToken('useNum')4", getToken('useNum'));
			//设置导航颜色
			if(this.moduleNo == 'ydylapp2003'){
				uni.setNavigationBarColor({
				    frontColor: '#ffffff',
				    backgroundColor: '#4e9ce6',
				    animation: {
				        duration: 400,
				        timingFunc: 'easeIn'
				    }
				})
			}else{
				// #ifdef H5
				uni.setNavigationBarColor({
					frontColor: '#ffffff',
					backgroundColor: '#ffffff',
					animation: {
						duration: 400,
						timingFunc: 'easeIn'
					}
				})
				// #endif
				// #ifdef MP-WEIXIN
				uni.setNavigationBarColor({
					frontColor: '#000000',
					backgroundColor: '#ffffff',
					animation: {
						duration: 400,
						timingFunc: 'easeIn'
					}
				})
				// #endif
			}
			this.initPage()
		},

		methods: {
			initPage() {
				if (!this.isLogin) {
					this.$store.dispatch('showAuthModal');
					return
				}
			}
		}
	}
</script>
<style scoped lang="scss">
	

</style>
